﻿using System;
using System.Collections.Generic;
using System.Text;
using SeoWebSite.BLL;
using System.Data;
using System.Configuration;
using Newtonsoft.Json.Linq;

namespace Modules
{
    public class QoPreferences
    {
        OS os = new OS();

        public int alert()
        {
            System.Diagnostics.Debug.Write("aaa");
            return 1;
        }

        public string saveAppearance()
        {
            return "";
        }

        public string saveAutorun()
        {
            return "";
        }
        public string saveBackground()
        {
            return "";
        }
        public string saveQuickstart()
        {
            return "";
        }
        public string saveShortcut()
        {
            return "";
        }

        public string viewThemes()
        {
            QOThemesBLL themesbll = new QOThemesBLL();
            DataSet ds = themesbll.get_active();
            if (ds.Tables[0].Rows.Count <= 0)
            {
                return "{success: false, themes: []}";
            }
            JArray items = new JArray();
            string theme_dir = ConfigurationManager.AppSettings["THEMES_DIR"];
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                JObject item = new JObject();
                JObject theme = JObject.Parse(dr["data"].ToString());
                item.Add("id", dr["id"].ToString());
                item.Add("group", (string)theme["group"]);
                item.Add("name", (string)theme["name"]);
                item.Add("thumbnail", theme_dir + (string)theme["thumbnail"]);
                item.Add("file", theme_dir + (string)theme["file"]);
                items.Add(item);
            }
            return "{success: true, themes: " + items.ToString() + "}";
        }

        public string viewWallpapers()
        {
            QOWallpapersBLL wallpapersbll = new QOWallpapersBLL();
            DataSet ds = wallpapersbll.get_active();
            if (ds.Tables[0].Rows.Count <= 0)
            {
                return "{success: false, wallpapers: []}";
            }
            JArray items = new JArray();
            string wallpaper_dir = ConfigurationManager.AppSettings["WALLPAPERS_DIR"];
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                JObject item = new JObject();
                JObject wallpaper = JObject.Parse(dr["data"].ToString());
                item.Add("id", dr["id"].ToString());
                item.Add("group", (string)wallpaper["group"]);
                item.Add("name", (string)wallpaper["name"]);
                item.Add("thumbnail", wallpaper_dir + (string)wallpaper["thumbnail"]);
                item.Add("file", wallpaper_dir + (string)wallpaper["file"]);
                items.Add(item);
            }
            return "{success: true, wallpapers: " + items.ToString() + "}";
        }
    }
}